//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "TestSurface.h"
using namespace Cephei::QL::Math;
#include <gen/QL/Math/Domain.h>
#include <gen/QL/Math/Surface.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::CTestSurface::CTestSurface (boost::shared_ptr<QuantLib::TestSurface>& childNative, Object^ owner) : CSurface(CTestSurface::typeid)
{
#ifdef HANDLE
	_phTestSurface = NULL;
#endif
	_ppTestSurface = &childNative;
    _ppSurface = new boost::shared_ptr<QuantLib::Surface> (boost::dynamic_pointer_cast<QuantLib::Surface> (*_ppTestSurface));
}
Cephei::QL::Math::CTestSurface::CTestSurface (QuantLib::TestSurface& childNative, Object^ owner) : CSurface(CTestSurface::typeid)
{
#ifdef HANDLE
	_phTestSurface = NULL;
#endif
	_ppTestSurface = new boost::shared_ptr<QuantLib::TestSurface> (&childNative);
    _ppSurface = new boost::shared_ptr<QuantLib::Surface> (boost::dynamic_pointer_cast<QuantLib::Surface> (*_ppTestSurface));
    _TestSurfaceOwner = owner;
    _SurfaceOwner = owner;
}

Cephei::QL::Math::CTestSurface::CTestSurface (CTestSurface^ copy) : CSurface(CTestSurface::typeid)
{
#ifdef HANDLE
	_phTestSurface = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppTestSurface = new boost::shared_ptr<QuantLib::TestSurface> (copy->GetShared());
        _ppSurface = new boost::shared_ptr<QuantLib::Surface> (boost::dynamic_pointer_cast<QuantLib::Surface> (*_ppTestSurface));
    }
}
Cephei::QL::Math::CTestSurface::CTestSurface (System::Type^ t) : CSurface(CTestSurface::typeid)
{
#ifdef HANDLE
	_phTestSurface = NULL;
#endif
	if (!t->IsSubclassOf(CTestSurface::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::CTestSurface::CTestSurface (QuantLib::Handle<QuantLib::TestSurface>& childNative, Object^ owner)  : CSurface(CTestSurface::typeid)
{
	_phTestSurface = &childNative;
	_ppTestSurface = &static_cast<boost::shared_ptr<QuantLib::TestSurface>>(childNative.currentLink());
    _ppSurface = new boost::shared_ptr<QuantLib::Surface> (boost::dynamic_pointer_cast<QuantLib::Surface> (*_ppTestSurface));
    _TestSurfaceOwner = owner;
}
Cephei::QL::Math::CTestSurface::CTestSurface (QuantLib::Handle<QuantLib::TestSurface> childNative)  : CSurface(CTestSurface::typeid)
{
	_phTestSurface = &childNative;
	_ppTestSurface = &static_cast<boost::shared_ptr<QuantLib::TestSurface>>(childNative.currentLink());
    _ppSurface = new boost::shared_ptr<QuantLib::Surface> (boost::dynamic_pointer_cast<QuantLib::Surface> (*_ppTestSurface));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::CTestSurface::CTestSurface (QuantLib::TestSurface childNative)  : CSurface(CTestSurface::typeid)
{
#ifdef HANDLE
	_phTestSurface = NULL;
#endif
	_ppTestSurface = new boost::shared_ptr<QuantLib::TestSurface> (new QuantLib::TestSurface (childNative));
    _ppSurface = new boost::shared_ptr<QuantLib::Surface> (boost::dynamic_pointer_cast<QuantLib::Surface> (*_ppTestSurface));
}
#endif

Cephei::QL::Math::CTestSurface::~CTestSurface ()
{
    if (_ppTestSurface != NULL)
    {
	    delete _ppTestSurface;
        _ppTestSurface = NULL;
    }
}
Cephei::QL::Math::CTestSurface::!CTestSurface ()
{
    if (_ppTestSurface != NULL)
    {
	    delete _ppTestSurface;
    }
}
QuantLib::TestSurface& Cephei::QL::Math::CTestSurface::GetReference ()
{
    if (_ppTestSurface == NULL) throw gcnew NativeNullException ();
	return **_ppTestSurface;
}
boost::shared_ptr<QuantLib::TestSurface>& Cephei::QL::Math::CTestSurface::GetShared ()
{
    if (_ppTestSurface == NULL) throw gcnew NativeNullException ();
	return *_ppTestSurface;
}
QuantLib::TestSurface* Cephei::QL::Math::CTestSurface::GetPointer ()
{
    if (_ppTestSurface == NULL) throw gcnew NativeNullException ();
	return &**_ppTestSurface;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::TestSurface>& Cephei::QL::Math::CTestSurface::GetHandle ()
{
	if (_phTestSurface == NULL)
	{
		_phTestSurface = new Handle<QuantLib::TestSurface> (*_ppTestSurface);
	}
	return *_phTestSurface;
}
#endif
bool Cephei::QL::Math::CTestSurface::HasNative () 
{
	return (_ppTestSurface != NULL);
}

Cephei::QL::Math::IDomain^ Cephei::QL::Math::CTestSurface::Domain::get ()
{
    try
    {
    	boost::shared_ptr<QuantLib::Domain> _rv = (boost::shared_ptr<QuantLib::Domain>)(*_ppTestSurface)->domain ( );   
        Cephei::QL::Math::CDomain^ _nrv = gcnew Cephei::QL::Math::CDomain (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

